/**
* @fileoverview 记录打卡记录
* @author Luoob
*/

import { Status } from './status'

const TIME_KEY = 'sign_record'

export type Record = {
  timeStamp: number
  status: Status
}

/**
 * 设置打卡时间
 */
function setTimeRecord(data: Record[] = []) {
  localStorage.setItem(TIME_KEY, JSON.stringify(data))
}

/**
 * 获取打卡记录
 */
export function getTimeRecord(): Record[] {
  return JSON.parse(localStorage.getItem(TIME_KEY) || '[]')
}

/**
 * 增加一条记录
 */
export function addRecord(record: Record) {
  const recordData = getTimeRecord()
  recordData.push(record)

  setTimeRecord(recordData)
}

/**
 * 重置记录数据
 */
export function resetRecord() {
  setTimeRecord([])
}